Array.prototype.my_splice = function(start, deleteCount, ...itemsToAdd) {
    const len = this.length;

    // 处理 start 参数
    start = start === undefined ? 0 : start;
    if (start < 0) {
        start = Math.max(len + start, 0);
    } else {
        start = Math.min(start, len);
    }

    // 处理 deleteCount 参数
    deleteCount = deleteCount === undefined ? len - start : deleteCount;
    deleteCount = Math.max(0, Math.min(deleteCount, len - start));

    // 保存被删除的元素
    const removedItems = this.slice(start, start + deleteCount);

    // 构造新的数组
    const leftPart = this.slice(0, start);
    const rightPart = this.slice(start + deleteCount);
    const newArr = [...leftPart, ...itemsToAdd, ...rightPart];

    // 清空当前数组并重新赋值
    this.length = 0;
    this.push(...newArr);

    // 返回被删除的元素
    return removedItems;
};

// 测试代码
let arr = ['a', 'b', 'c', 'd', 'e'];
const res = arr.my_splice(1, 2, 'x', 'y', 'z');
console.log(res); // ['b', 'c']
console.log(arr); // ['a', 'x', 'y', 'z', 'd', 'e']